<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>	
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<head>
<title>preOrders</title>
<%@include file="../../common.jsp"%>
</head>
<div>
	<div id="content_div">
		<header class="contHeader">
			<div class="contOHeader" style="z-index: 100">
				<h1>订单结算页</h1>
				<div class="contOHeadBack">
					<a href="javascript:history.go(-1);"><img src="${staticPath}/images/back2.png"></a>
				</div>
			</div>
		</header>
		<input type="hidden" id="noneedExpressCode" value="${noneedExpressCode}"/>
		<form id="order_form" method="post" action="">
			<div class="tjdd"></div>
			<div class="weui_cells weui_cells_access" id="address_div">
				<input type="hidden" id="addressId" name="addressId" value="${address.id}" /> 
					<a class="weui_cell" href="javascript:;">
					<div class="weui_cell_bd weui_cell_primary">
						<c:choose>
							<c:when test="${address==null}">
								<input type="hidden" id="addressIsNull" value="1" />
								<div>您还没有设置收货地址，请添加收货地址！</div>
							</c:when>
							<c:otherwise>
								<img src="${staticPath}/images/dz.png" class="float dz">
								<h5>
									收件人：<span id="receiver">${address.name}</span>
								</h5>
								<p class="font12">
									送货地址：<span id="address">${address.address}</span>
								</p>
							</c:otherwise>
						</c:choose>
					</div>
					<div class="weui_cell_ft"></div>
					</a>
			</div>
			<c:set var="goodsTotal" value="0" />
			<c:set var="goodsAmount" value="0" />
			<c:set var="goodsPoints" value="0" />
			<c:forEach items="${cartItemsGroupByStorageId}" var="cartItems" varStatus="storageStatus">
				<div class="weui_cells_title">${cartItems.value[0].goods.storage.name}</div>
				<div class="weui_cells weui_cells_access">
					<c:set var="storageGoodsTotal" value="0"></c:set>
					<c:set var="storageGoodsAmount" value="0"></c:set>
					<c:set var="storageGoodsPointsAmount" value="0"></c:set>
					<c:forEach items="${cartItems.value}" var="cartIem" varStatus="cartItemStatus">
						<a class="weui_cell" href="javascript:;" style="border-bottom: #ddd 1px dashed;">
							<div class="weui_cell_hd">
								<img src="${cartIem.goodsImage}" alt="" style="width: 60px; height: 60px; margin-right: 5px; display: block">
							</div>
							<div class="weui_cell_bd weui_cell_primary">
								<p>${cartIem.goodsName}</p>
								<h4>
									<c:choose>
										<c:when test="${'1'==pointBuyFlag}">
											积分：${cartIem.sku.points}
										</c:when>
										<c:otherwise>
											￥<fmt:formatNumber value="${cartIem.goodsPrice/100}" pattern="0.00" />
										</c:otherwise>
									</c:choose>
								</h4>
								<p>X${cartIem.goodsNum}</p>
								<c:set var="storageGoodsTotal" value="${storageGoodsTotal+cartIem.goodsNum}"></c:set>
								<c:set var="storageGoodsAmount" value="${storageGoodsAmount+cartIem.goodsPrice*cartIem.goodsNum}"></c:set>
								<c:set var="storageGoodsPointsAmount" value="${storageGoodsPointsAmount+cartIem.sku.points*cartIem.goodsNum}"></c:set>
							</div>
						</a>
						<input type="hidden" name="storageOrderInfoList[${storageStatus.index}].carts[${cartItemStatus.index}].skuId" value="${cartIem.sku.id}" />
						<input type="hidden" name="storageOrderInfoList[${storageStatus.index}].carts[${cartItemStatus.index}].num" value="${cartIem.goodsNum}" />
					</c:forEach>
					<input type="hidden" name="storageOrderInfoList[${storageStatus.index}].storageId" value='${fn:replace(cartItems.key, "storage","")}' />
					<div>
						<div class="tjleft">
							<p>共${storageGoodsTotal}件</p>
						</div>
						<div class="tjmid">
							<c:choose>
								<c:when test="${'1'==pointBuyFlag}">
									<p>商品积分：</p>
								</c:when>
								<c:otherwise>
									<p>商品金额：</p>
								</c:otherwise>
							</c:choose>
						</div>
						<div class="tjright">
							<p>
								<c:choose>
									<c:when test="${'1'==pointBuyFlag}">
											${storageGoodsPointsAmount}
										</c:when>
									<c:otherwise>
										￥
										<fmt:formatNumber value="${storageGoodsAmount/100}" pattern="0.00" />
									</c:otherwise>
								</c:choose>
							</p>
						</div>
					</div>
				</div>
				<!-- 仓库快递 -->
				<div class="weui_cell weui_cell_select" style="width: 95%;border-top: none;">
					<div class="weui_cell_bd weui_cell_primary">
						<c:set value='${fn:replace(cartItems.key, "storage", "storageExpress")}' var='storageExpressKey' />
						<select class="weui_select express-select" name="storageOrderInfoList[${storageStatus.index}].expressId" >
							<c:forEach items="${expressGroupByStorageId[storageExpressKey]}" var="express">
								<option value="${express[1]}" code="${express[2]}">${express[3]}</option>
							</c:forEach>
						</select>
					</div>
				</div>
				<div class="weui_cell" style="width: 88%">
					<div class="weui_cell_hd">
						<label class="weui_label msg_label">给卖家留言：</label>
					</div>
					<div class="weui_cell_bd weui_cell_primary" >
						<input maxlength="120" class="weui_input msg_input"  name="storageOrderInfoList[${storageStatus.index}].remark" placeholder="选填:(建议填写已和卖家协商一致的内容)">
					</div>
				</div>
				<div class="clear" style="width: 100%; height:1px; border-top: 1px solid #d9d9d9;"></div>
				<c:set var="goodsTotal" value="${goodsTotal+storageGoodsTotal}" />
				<c:set var="goodsAmount" value="${goodsAmount+storageGoodsAmount}" />
				<c:set var="goodsPoints" value="${goodsPoints+storageGoodsPointsAmount}" />
			</c:forEach>
			<!--  代金券 -->
	        <c:if test="${voucherList!=null&&fn:length(voucherList)>0}">
       		 <input type="hidden"  id="voucherId" name="voucherId" />
	         <div class="clear" style="clear: both;height: 10px;background-color: #CCCCCC "></div>
	         <div class="weui_cells weui_cells_access" style="">
				<a class="weui_cell" href="javascript:chooseVoucher();" style="height: 30px">
				<div class="weui_cell_bd weui_cell_primary">
					<p class="font12" style="font-size: 14px; color: #252525">
						优惠券
					</p>
				</div>
				<div id="show_voucher" class="weui_cell_ft" style="font-size: 14px; color: #252525">未使用</div>
				</a>
			 </div>
				<div id="voucher_div"  style="display: none">
					<div class="weui-popup-overlay"></div>
					<div class="weui-popup-modal" style="background-color: #f8f8f8">
					<div class="weui_cells_title " style="border-bottom: 1px solid #d9d9d9;">可用代金券</div>
			        	<c:forEach items="${voucherList}" var ="voucher">
			        		<div id="voucher${voucher.id}" class="weui_cells weui_cells_access voucher-div" style="padding-left: 15px;" onclick="javascript:returnChoosed('${voucher.id}','${voucher.price}');">
								<div class="weui_cell_bd weui_cell_primary">
									<h5>满<fmt:formatNumber value="${(voucher.limitMoney-voucher.limitMoney%100)/100}" type="NUMBER"></fmt:formatNumber>减<fmt:formatNumber value="${(voucher.price-voucher.price%100)/100}" type="NUMBER" ></fmt:formatNumber></h5>
									<p class="font12">有效期至：<fmt:formatDate value="${voucher.endDate}" pattern="yyyy-MM-dd HH:mm:ss" /> </p>
								</div>
			        		</div>
			        	</c:forEach>
			        	<div style="clear: both;height: 10px;"></div>
			        	<a href="javascript:returnChoosed(null);" class="weui_btn weui_btn_plain_primary close-popup " style="width: 80%">关闭</a>
		        	</div>
	        	</div>
	        </c:if>
	        <div class="clear" style="clear: both;"></div>
			<c:if test="${activityInfoList!=null&&fn:length(activityInfoList)>0}">
				<!-- 赠品 -->
		        <div class="clear" style="width: 100%;height:10px; border-bottom: 1px solid #d9d9d9;"></div>
				<div  id="activity_div" class="weui_cell weui_cell_select" style="width: 95%;margin:0;border-top: none;" >
					<div class="weui_cell_bd weui_cell_primary">
						<input type="hidden" name="activityId" id="activityId" />
						<select class="weui_select express-select"  onchange="getActivityInfo(this)" >
							<option value="-1" selected="selected" >不使用活动优惠</option>
							<c:forEach items="${activityInfoList}" var="activity">
								<option value="${activity[0]},${activity[3]}">${activity[1]}</option>
							</c:forEach>
						</select>
					</div>
				</div>
		        <div class="clear" style="width: 100%; border-top: 1px solid #d9d9d9;"></div>
				<input type="hidden" value="" name="giftSkuId" id="giftSkuId"/> 
				<div id="choosed_gift_div" style="margin: 5px;"></div>
			</c:if>
			<div id="order_gift_div" class="weui-popup-container"></div>
			<div class="clear" style="clear: both;"></div>
			<div class="weui_cells weui_cells_access" style="margin-top: 10px; background: #f5f5f5;">
				<div class="tjleft">
					<p>共${goodsTotal}件</p>
				</div>
				<c:choose>
					<c:when test="${'1'==pointBuyFlag}">
						<div class="tjmid">
							<p>商品积分：</p>
						</div>
						<div class="tjright">
							<p>
								${goodsPoints}
							</p>
						</div>
					</c:when>
					<c:otherwise>
						<div class="tjmid">
							<p>商品金额：</p>
						</div>
						<div class="tjright">
							<p>
								￥
								<fmt:formatNumber value="${goodsAmount/100}" pattern="0.00" />
							</p>
						</div>
					</c:otherwise>
				</c:choose>
			</div>
			<div class="clear" style="clear: both; height: 42px;"></div>
			<div class="tabm">
				<c:choose>
					<c:when test="${'1'==pointBuyFlag}">
						<h4 class="tableft">
							商品积分：<span class="tableft11">${goodsPoints}</span>
							<input type="hidden" id="consumePoints" value="${goodsPoints}"/>
							<input type="hidden" id="userPoints" value="${userPoints}"/>
						</h4>
					</c:when>
					<c:otherwise>
						<h4 class="tableft">
							商品总额：<span class="tableft11">￥<fmt:formatNumber value="${goodsAmount/100}" pattern="0.00" /></span>
						</h4>
					</c:otherwise>
				</c:choose>
				<a class="tabright" href="javascript:void(0)" id="submit_order">提交订单</a>
			</div>
			<input type="hidden" name="token" id="token-input" />
			<input type="hidden" name="pointBuyFlag" id="pointBuyFlag" value="${pointBuyFlag}" />
		</form>
		<input type="hidden" value="${synchronizeCookieStr}" id="synchronizeCookieStr" />
	</div>
</div>     
